import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getUserInfoServer } from '@/api/user'
export const useUserStore = defineStore('big-user', () => {
  //用户登录凭证管理
  const token = ref(0)
  const setToken = (value) => {
    token.value = value
  }
  const removeToken = () => {
    token.value = null
  }
  // 用户信息管理
  const user = ref(null)
  const getUser = async () => {
    const res = await getUserInfoServer()
    user.value = res.data
    // console.log(user.value)
  }
  const setUser = (userInfo) => {
    user.value = userInfo
  }
  return { token, setToken, removeToken, user, getUser, setUser }
},
  {
    persist: true
  }
)
